package cn.edu.zucc.controller;

import cn.edu.zucc.entity.TComment;
import cn.edu.zucc.mapper.TCommentMapper;
import cn.edu.zucc.service.TCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description t_comment
 * @author zhengkai.blog.csdn.net
 * @date 2022-04-17
 */
@CrossOrigin
@RestController
@RequestMapping(value = "/tComment")
public class TCommentController {

    @Resource
    private TCommentService tCommentService;

//    @Resource 不行 需要Autowired
    @Autowired
    TCommentMapper commentMapper;
/**
* id 存在就更新 不然插入
* @param tComment
* @return
*/
@PostMapping("/save")
public Object save(@RequestBody TComment tComment){
return tCommentService.save(tComment);
}

    /**
    * 新增
    * @author zhengkai.blog.csdn.net
    * @date 2022/04/17
    **/
    @PostMapping("/insert")
    public Object insert(TComment tComment){
        return tCommentService.insert(tComment);
    }

    /**
    * 刪除
    * @author zhengkai.blog.csdn.net
    * @date 2022/04/17
    **/
    @PostMapping("/delete")
    public Object delete(int id){
        return tCommentService.delete(id);
    }

    /**
    * 更新
    * @author zhengkai.blog.csdn.net
    * @date 2022/04/17
    **/
    @PostMapping("/update")
    public Object update(TComment tComment){
        return tCommentService.update(tComment);
    }

    /**
    * 查询 根据主键 id 查询
    * @author zhengkai.blog.csdn.net
    * @date 2022/04/17
    **/
    @PostMapping("/getById")
    public Object getById(Integer id){
        return tCommentService.getById(id);
    }

//    @PostMapping("/getById")
//    public Object getById(Integer id){
//        return tCommentService.getById(id);
//    }

    @PostMapping("/getByArticleId")
    public Object getByStuId(@RequestBody  TComment tComment){
//        eduExpService.pageList()
//        artcle Id 不是
        List<TComment> comments = commentMapper.selectByArticleId(tComment.getAid());
        System.out.println("comments");
        System.out.println(comments);
//        EduExpExample eduExpExample = new EduExpExample();
//        eduExpExample.createCriteria().
//         eduExpExample.createCriteria().andStuIdEqualTo(eduExp.getStuId());
//        return eduExpMapper.selectByExample(eduExpExample);
        Map<String ,Object>map=new HashMap<>();
        map.put("content",comments);
//        return eduExps;
        return map;
    }
    /**
    * 查询 分页查询
    * @author zhengkai.blog.csdn.net
    * @date 2022/04/17
    **/
    @PostMapping("/list")
    public Map<String, Object> pageList(@RequestParam(required = false, defaultValue = "0") int pageNumber,
                                        @RequestParam(required = false, defaultValue = "10") int pageSize) {
        return tCommentService.pageList(pageNumber, pageSize);
        //Map<String, Object> pageList = tCommentService.pageList(pageNumber, pageSize);
//return ReturnT.success(pageList);
    }

}
